package com.bjc.scheduler.elasticjob.springboot.config;

import com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: elastic-job-springboot
 * @description:
 * @author: bjc
 * @create: 2021-08-15 21:05
 */
@Configuration
public class ElasticJobRegistryCenterConfig {
    /**
     * zookeeper连接地址
     */
    private String ZOOKEEPER_CONNECTION_STRING = "localhost:2181";

    /**
     * 定时任务命名空间
     */
    private String JOB_NAMESPACE = "elastic-job-example-java";

    /**
     * 注册中心配置  initMethod:初始化调用 “init”方法
     * @return
     */
    @Bean(initMethod = "init")
    public CoordinatorRegistryCenter setUpRegistryCenter(){
        ZookeeperConfiguration zookeeperConfiguration = new ZookeeperConfiguration(ZOOKEEPER_CONNECTION_STRING, JOB_NAMESPACE);
        //减少zk的超时时间
        zookeeperConfiguration.setSessionTimeoutMilliseconds(100);
        //创建注册中心
        ZookeeperRegistryCenter registryCenter = new ZookeeperRegistryCenter(zookeeperConfiguration);
        return registryCenter;
    }
}
